package com.jinyang.jetpackdemo.activity

import android.content.res.Configuration
import android.os.Bundle
import android.os.PersistableBundle
import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.jinyang.jetpackdemo.R
import com.jinyang.jetpackdemo.databinding.ActivityConsultationServiceBinding
import com.jinyang.jetpackdemo.util.LjyLogUtil

class ConsultationServiceActivity : AppCompatActivity() {

    private lateinit var binding: ActivityConsultationServiceBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        LjyLogUtil.d("Activity.onCreate:${savedInstanceState}")
        binding = ActivityConsultationServiceBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val navView: BottomNavigationView = binding.navView

        val navController = findNavController(R.id.nav_host_fragment_activity_consultation_service)
        val appBarConfiguration = AppBarConfiguration(
            setOf(
                R.id.navigation_home, R.id.navigation_dashboard
            )
        )
        setupActionBarWithNavController(navController, appBarConfiguration)
        navView.setupWithNavController(navController)
    }

    override fun onStart() {
        super.onStart()
        LjyLogUtil.d("Activity.onStart")
    }

    override fun onRestart() {
        super.onRestart()
        LjyLogUtil.d("Activity.onRestart")
    }

    override fun onResume() {
        super.onResume()
        LjyLogUtil.d("Activity.onResume")
    }

    override fun onPause() {
        super.onPause()
        LjyLogUtil.d("Activity.onPause")
    }

    override fun onStop() {
        super.onStop()
        LjyLogUtil.d("Activity.onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        LjyLogUtil.d("Activity.onDestroy")
    }

    //重写单参的才执行
    //override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        LjyLogUtil.d("Activity.onSaveInstanceState")
        outState.putString("key1","value1")
        outState.putString("key2","value2")
    }

    //若 异常关闭了Activity，即调用了onSaveInstanceState（） & 下次启动时会调用onRestoreInstanceState（）
    //若是 被用户主动销毁（如 用户按Back键），则不会调用
    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        LjyLogUtil.d("Activity.onRestoreInstanceState:${savedInstanceState}")
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        LjyLogUtil.d("Activity.onConfigurationChanged:${newConfig}")
    }
}